<template>

  <div class="app-container" style="font-size:12px">
    <div class="filter-container">
      <el-input v-model="listQuery.real_name" placeholder="客户姓名" style="width: 100px;margin-top:6px" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-select v-model="listQuery.status" placeholder="状态" class="filter-item" style="width:130px;margin-top:8px">
        <el-option label="状态" :value="0" />
        <el-option label="未处理" :value="1"/>
        <el-option label="已处理" :value="2"/>
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" style="margin-top:6px" @click="handleFilter">查询</el-button>
      <!-- <excelout /> -->
    </div>

    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;margin-top:20px">
      <el-table-column label="客户姓名" align="center" width="200">
        <template slot-scope="{row}">
          <!-- {{ row.create_time|formatDate}} -->
          {{ row.real_name }}
        </template>
      </el-table-column>
      <el-table-column label="门店" align="center" width="300">
        <template slot-scope="{row}">
          <span>{{ row.c_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车牌" align="center" width="300">
        <template slot-scope="{row}">
          <span>{{ row.plate_no }}</span>
        </template>
      </el-table-column>
      <el-table-column label="期数" align="center" width="80">
        <template slot-scope="{row}">
          <span>{{ row.num }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="客户电话" align="center" width="110">
        <template slot-scope="{row}">
          <span>{{ row.mobile }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="发票金额" align="center" width="80">
        <template slot-scope="{row}">
          <span>{{ row.total_money+money_rate }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="租金" align="center" width="80">
        <template slot-scope="{row}">
          <span>{{ row.total_money }}</span>
        </template>
      </el-table-column>
      <el-table-column label="加融" align="center" width="80">
        <template slot-scope="{row}">
          <span>{{ row.money_rate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="还款日期" align="center" width="120">
        <template slot-scope="{row}">
          <span>{{ row.paid_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="邮箱" align="center" width="300">
        <template slot-scope="{row}">
          <span>{{ row.email }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发票状态" align="center" width="100">
        <template slot-scope="{row}">
          <span v-if="row.status==1">未处理</span>
          <span v-if="row.status==2">已处理</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="{row}">
          <el-dropdown-item>
            <el-button type="primary" v-if="row.status==1" size="mini" @click="changeStatus(row.id)">
              更改状态
            </el-button>
          </el-dropdown-item>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

  </div>

</template>

<script>
import excel from '@/components/excelout/index.vue'

import {
  exceloutserver,invoice,changeStatus
} from '@/api/finance'
import { formatDate } from '@/utils/formatDate.js'
import { merchantListOnlyMerchant } from '@/api/merchant'
import { fetchList } from '@/api/sale'
import waves from '@/directive/waves' // waves directive
import {
  parseTime
} from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
export default {
  name: 'ComplexTable',
  components: {
    Pagination, excel
  },
  directives: {
    waves
  },
  filters: {
   	formatDate(time) {
   	        time = time * 1000
   	        const date = new Date(time)

   	        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
   	      }
  },
  data() {
    return {
      form: {
        payway: '',
        order_id: '',
        serverMoneyNun: '',
        serverMoneyBack: '',
        desc: '',
        return: '',
        buyout: '',
        hold_first: '',
        bond: '',
        pay_time: ''
      },
      tableKey: 0,
      returnOrderAble: false,
      channelChooseAble: false,
      serverAble: false,
      title: ['账户列表', '已选列表'],
      tableRecord: 1,
      list: null,
      channelList: [],
      allcount: [],
      record_list: null,
      listRecordLoading: true,
      recordTotal: 0,
      total: 0,
      listLoading: true,
      city: [],
      choose: [],
      payway: [],
      listQuery: {
        page: 1,
        limit: 10,
        real_name: '',
        status: 0
      },
      listRecordQuery: {
        page: 1,
        limit: 20,
        order_id: ''
      },
      listMerchantQuery: {
        page: 1,
        limit: 500
      },
      textMap: {
        record: '订单记录',
        create: 'Create'
      },
      merchant_list: [],
      sale_list: [],
      dialogRecordVisible: false,
      dialogStatus: '',
      downloadLoading: false
    }
  },
  created() {
    this.cacheQueryFormat()
    this.getList()
    this.getMerchantList()
    this.getPayWay()
    // 添加钩子，页面刷新
    window.addEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  destroyed() {
    // 添加钩子，页面刷新
    window.removeEventListener('beforeunload', e => this.beforeunloadFn(e))
  },
  methods: {
    beforeunloadFn(e) {
      // 刷新页面事件
      sessionStorage.removeItem('financeInvoiiceList')
    },
    cacheQueryFormat() {
      const cacheQuery = sessionStorage.getItem('financeInvoiiceList')
      if (cacheQuery) {
        this.listQuery = JSON.parse(cacheQuery)
      }
    },
    getList() {
      sessionStorage.setItem('financeInvoiiceList', JSON.stringify(this.listQuery))
      invoice(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 0.1 * 1000)
      })
    },

    changeStatus(v_id) {
      let pam = {id:v_id}
      this.$confirm('确认已处理该数据吗, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        changeStatus(pam).then(response => {
          this.$message({
            type: 'success',
            message: '成功!'
          })
          this.getList()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
  
    handleFilter() {
      this.listLoading = true
      this.listQuery.page = 1
      console.log(this.listQuery);
      this.getList()
    },
  
    excelout() {
      this.listLoading = true
      this.listQuery.page = 1
      this.listQuery.limit = this.total
      exceloutserver(this.listQuery).then(response => {
        this.listLoading = false
        const filepath = response.data.path
        window.location.href = filepath
      })
    },
  
  }
}
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
  }
  td{padding: 0;}
  select{
    width:100px;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
    float: left;
  }
   .el-table .warning-row {
      background: orangered;
    }

  .el-table .success-row {
    background: #98dd72;
  }
  .el-table .default-row {
    background: #ccc;
  }
</style>
